<?php

namespace App\Console\Commands\OpenShop;

use App\Models\Common\MapNationalIndustrialParkModel;
use App\Models\Common\MapNationalStreetModel;
use App\Models\Common\MapNationalUniversitiesModel;
use App\Models\Common\MapTownshipPlanAreaModel;
use App\Models\OpenShop\Common\SiteLocationMallModel;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationExamineLogModel;
use Illuminate\Console\Command;

class ReviseDotStatus extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'wanggui:revise-dot-status';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '修正网规点位状态';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        OpenShopSiteLocationExamineLogModel::query()
            ->where('source', OpenShopSiteLocationExamineLogModel::SOURCE_WG_AUDIT)
            ->get()
            ->map(function (OpenShopSiteLocationExamineLogModel $examineLogModel) {
                 //获得前两位
                $prefix = substr($examineLogModel->orderNo, 0, 2);
                switch ($prefix) {
                    case "SC":
                        SiteLocationMallModel::query()
                            ->where('wgNumber', $examineLogModel->orderNo)
                            ->update([
                                'status' => $examineLogModel->status
                            ]);
                        break;
                    case "XZ":
                         MapTownshipPlanAreaModel::query()
                            ->where('wgNumber', $examineLogModel->orderNo)
                            ->update([
                                'status' => $examineLogModel->status
                            ]);
                        break;
                    case "JD":
                         MapNationalStreetModel::query()
                            ->where('wgNumber', $examineLogModel->orderNo)
                            ->update([
                                'status' => $examineLogModel->status
                            ]);
                        break;
                    case "CY":
                         MapNationalIndustrialParkModel::query()
                            ->where('wgNumber', $examineLogModel->orderNo)
                            ->update([
                                'status' => $examineLogModel->status
                            ]);
                        break;
                    case "GX":
                         MapNationalUniversitiesModel::query()
                            ->where('wgNumber', $examineLogModel->orderNo)
                            ->update([
                                'status' => $examineLogModel->status
                            ]);
                        break;
                }
            });
    }
}
